import pandas as pd
import os
os.environ["OMP_NUM_THREADS"] = "1"
import plotly.express as px
import plotly.graph_objects as go
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.cluster import KMeans
import numpy as np
from scipy.stats import zscore
from scipy.cluster.hierarchy import linkage, dendrogram, fcluster
import plotly.figure_factory as ff
from scipy.cluster.hierarchy import linkage
import matplotlib.pyplot as plt
from sklearn.metrics import silhouette_score
import matplotlib.ticker as ticker
import plotly.graph_objects as go
pd.set_option('display.float_format', '{:,.2f}'.format)
df_volaille_brut = pd.read_csv("df_final.csv")
df_volaille_brut.head()
| Unnamed: 0 | Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | Afghanistan | 0.00 | -2.79 | 4.16 | 2,956.80 | 57.00 | 0.00 | 29.00 | 55.00 | 2.00 | 28.00 | 57.00 | 36,296,113.00 | 2017 | 2.66 | 2.24 |
| 1 | 1 | Afrique du Sud | 0.00 | -0.28 | 0.82 | 14,823.60 | 2,118.00 | 63.00 | 514.00 | 2,035.00 | 83.00 | 1,667.00 | 2,181.00 | 57,009,756.00 | 2017 | 1.36 | -16.23 |
| 2 | 2 | Algérie | 0.00 | -0.92 | 1.00 | 13,805.40 | 277.00 | 0.00 | 2.00 | 264.00 | 13.00 | 275.00 | 277.00 | 41,389,189.00 | 2017 | 1.77 | -1.56 |
| 3 | 3 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 4 | 4 | Angola | 0.01 | -0.39 | 0.81 | 9,050.00 | 319.00 | 0.00 | 277.00 | 315.00 | 2.00 | 42.00 | 319.00 | 29,816,766.00 | 2017 | 3.32 | 2.80 |
df_volaille_brut = df_volaille_brut.drop(columns="Unnamed: 0")
len(df_volaille_brut)
103
colonnes = [
'PIB par habitant',
'Disponibilité intérieure',
'Exportations - Quantité',
'Importations - Quantité',
'Nourriture',
'Pertes',
'Production',
'émission N2O / production',
'Stabilité politique en 2017',
'croissance du PIB en %',
'Population',
'croissance de la population en %',
'croissance de la stabilité politique en %'
]
X = df_volaille_brut[colonnes]
X = X.replace([np.inf, -np.inf], np.nan)
X_clean = X.fillna(X.mean())
X_clean = X.fillna(X.mean())
scaler = StandardScaler()
X_std = scaler.fit_transform(X_clean)
scaled_df = pd.DataFrame(X_std, columns=colonnes)
scaled_df["émission N2O / production"] *= -1
pca_full = PCA().fit(X_std)
cum_var = np.cumsum(pca_full.explained_variance_ratio_)
plt.plot(range(1, len(cum_var)+1), cum_var, marker='o')
plt.xlabel("Nombre de composantes")
plt.ylabel("Variance cumulée")
plt.title("Variance expliquée cumulée (PCA)")
plt.grid(True)
plt.axhline(0.9, color='red', linestyle='--')
plt.show()
pca = PCA(n_components=8)
X_pca = pca.fit_transform(X_std)
pc_columns = [f'PC{i+1}' for i in range(X_pca.shape[1])]
df_pca = pd.DataFrame(X_pca, columns=pc_columns)
df_pca['Zone'] = df_volaille_brut['Zone'].values
z_scores = df_pca[[f'PC{i}' for i in range(1, 4)]].apply(zscore)
df_pca_filtered = df_pca[(z_scores.abs() < 3).all(axis=1)]
df_pca_outliers = df_pca[(z_scores.abs() >= 3).any(axis=1)]
fig = px.scatter(
df_pca_filtered,
x='PC1',
y='PC2',
color='Zone',
title='ACP - Plan factoriel (PC1 vs PC2)',
labels={'PC1': 'Composante principale 1', 'PC2': 'Composante principale 2'},
width=900,
height=600
)
fig.update_traces(marker=dict(size=8))
fig.update_layout(legend_title_text='Zone')
fig.show()
df_pca_outliers
| PC1 | PC2 | PC3 | PC4 | PC5 | PC6 | PC7 | PC8 | Zone | |
|---|---|---|---|---|---|---|---|---|---|
| 14 | 10.37 | 0.09 | -4.00 | -1.09 | 0.31 | -2.36 | 0.28 | 0.04 | Brésil |
| 40 | 4.48 | 8.52 | 7.22 | 0.19 | 4.75 | -0.08 | 0.60 | -0.36 | Inde |
| 84 | -1.48 | 2.19 | -4.58 | 4.71 | 3.48 | 3.11 | -0.13 | 3.41 | Soudan |
| 102 | 15.08 | -1.28 | -2.04 | -1.35 | -0.80 | 2.67 | 0.53 | 0.34 | États-Unis d'Amérique |
variance = pca.explained_variance_ratio_
print(f"Variance expliquée par PC1 : {variance[0]:.2%}")
print(f"Variance expliquée par PC2 : {variance[1]:.2%}")
print(f"Variance expliquée par PC3 : {variance[2]:.2%}")
Variance expliquée par PC1 : 31.76% Variance expliquée par PC2 : 18.07% Variance expliquée par PC3 : 12.46%
df_pca_filtered
| PC1 | PC2 | PC3 | PC4 | PC5 | PC6 | PC7 | PC8 | Zone | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | -1.06 | 2.41 | -1.37 | 0.14 | -0.96 | 0.32 | -0.97 | -0.27 | Afghanistan |
| 1 | 0.87 | -0.03 | 0.49 | 1.15 | 0.12 | -0.28 | -1.13 | -0.62 | Afrique du Sud |
| 2 | -0.70 | 0.57 | -0.69 | 0.16 | 0.13 | 0.18 | 0.24 | -0.71 | Algérie |
| 3 | 1.41 | -2.33 | 1.50 | 0.94 | -0.11 | -0.30 | -2.19 | 0.09 | Allemagne |
| 4 | -0.71 | 0.06 | -0.51 | 0.96 | 0.20 | 0.28 | -0.51 | -0.23 | Angola |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 97 | -0.97 | 0.53 | -0.55 | -0.28 | -0.03 | -0.07 | 0.23 | 0.53 | Zambie |
| 98 | -0.97 | 1.00 | -0.59 | -0.47 | -0.56 | -0.14 | -0.07 | -0.02 | Zimbabwe |
| 99 | -0.04 | 1.01 | -0.63 | 0.29 | -0.31 | 0.49 | -0.43 | -0.58 | Égypte |
| 100 | -0.20 | -2.70 | 0.18 | 1.92 | 1.79 | 0.67 | -0.29 | 0.07 | Émirats arabes unis |
| 101 | -0.80 | 0.17 | -0.07 | -0.32 | -0.17 | 0.78 | 0.46 | -0.22 | Équateur |
99 rows × 9 columns
loadings = pca.components_.T * np.sqrt(pca.explained_variance_)
cor_df = pd.DataFrame(loadings[:, :2], columns=['PC1', 'PC2'], index=colonnes).reset_index()
cor_df.rename(columns={'index': 'Variable'}, inplace=True)
fig = go.Figure()
angle = np.linspace(0, 2 * np.pi, 100)
fig.add_scatter(x=np.cos(angle), y=np.sin(angle), mode='lines',
line=dict(color='lightgray', dash='dot'),
name='Cercle unité', showlegend=False)
for _, row in cor_df.iterrows():
fig.add_scatter(x=[0, row['PC1']], y=[0, row['PC2']],
mode='lines+text',
text=[None, row['Variable']],
textposition='top center',
line=dict(width=2),
showlegend=False)
fig.update_layout(
title='Cercle des corrélations - ACP',
width=700, height=700,
xaxis=dict(title='Composante principale 1', range=[-1.1, 1.1], zeroline=True),
yaxis=dict(title='Composante principale 2', range=[-1.1, 1.1], zeroline=True),
shapes=[
dict(type='line', x0=-1, y0=0, x1=1, y1=0, line=dict(color='gray')),
dict(type='line', x0=0, y0=-1, x1=0, y1=1, line=dict(color='gray'))
]
)
fig.show()
loadings_3d = loadings[:, [0, 1, 2]]
cor_df = pd.DataFrame(loadings_3d, columns=['PC1', 'PC2', 'PC3'], index=colonnes).reset_index()
cor_df.rename(columns={'index': 'Variable'}, inplace=True)
fig = go.Figure()
for _, row in cor_df.iterrows():
fig.add_trace(go.Scatter3d(
x=[0, row['PC1']],
y=[0, row['PC2']],
z=[0, row['PC3']],
mode='lines+text',
text=[None, row['Variable']],
textposition='top center',
name=row['Variable'],
line=dict(width=4)
))
fig.update_layout(
scene=dict(
xaxis_title='PC1',
yaxis_title='PC2',
zaxis_title='PC3',
xaxis=dict(range=[-1.1, 1.1]),
yaxis=dict(range=[-1.1, 1.1]),
zaxis=dict(range=[-1.1, 1.1]),
),
title='Sphère des corrélations - ACP (PC1, PC2, PC3)',
width=800,
height=800
)
fig.show()
df_pca_filtered = df_pca[(z_scores.abs() < 3).all(axis=1)]
df_pca['Zone'] = df_volaille_brut['Zone'].values
fig = px.scatter_3d(
df_pca_filtered,
x='PC1',
y='PC2',
z='PC3',
color='Zone',
title='ACP - Projection 3D des individus (PC1, PC2, PC3)',
labels={
'PC1': 'Composante principale 1',
'PC2': 'Composante principale 2',
'PC3': 'Composante principale 3'
},
width=900,
height=700
)
fig.update_traces(marker=dict(size=5))
fig.update_layout(legend_title_text='Zone')
fig.show()
Z = linkage(X_std, method='ward')
k = 5
labels = fcluster(Z, k, criterion='maxclust')
df_cluster = pd.DataFrame()
plt.figure(figsize=(12, 6))
dendrogram(Z, truncate_mode='lastp', p=30, show_leaf_counts=True, leaf_rotation=90, leaf_font_size=10)
plt.title("Dendrogramme tronqué (30 derniers clusters fusionnés)")
plt.ylabel("Distance")
plt.tight_layout()
plt.show()
os.environ["OMP_NUM_THREADS"] = "1"
inerties = []
k_range = range(1, 11)
for k in k_range:
X = X.replace([np.inf, -np.inf, np.nan], 0)
kmeans = KMeans(n_clusters=k, n_init=10, random_state=42)
kmeans.fit(X)
inerties.append(kmeans.inertia_)
plt.figure(figsize=(8, 4))
plt.plot(k_range, inerties, marker='o')
plt.title("Méthode du coude")
plt.xlabel("Nombre de clusters (k)")
plt.ylabel("Inertie intra-cluster")
plt.grid(True)
plt.show()
range_k = range(2, 11) # k doit être ≥ 2
scores = []
# Utiliser les données filtrées par PCA
for k in range_k:
kmeans = KMeans(n_clusters=k, n_init=10, random_state=42)
labels = kmeans.fit_predict(df_pca_filtered[pc_columns])
# Calcul du silhouette score
score = silhouette_score(df_pca_filtered[pc_columns], labels)
scores.append(score)
print(f"k = {k}, silhouette = {score:.4f}")
k = 2, silhouette = 0.2829 k = 3, silhouette = 0.2833 k = 4, silhouette = 0.2823 k = 5, silhouette = 0.3057 k = 6, silhouette = 0.2532 k = 7, silhouette = 0.2568 k = 8, silhouette = 0.2331 k = 9, silhouette = 0.2342 k = 10, silhouette = 0.2706
plt.figure(figsize=(8, 4))
plt.plot(range_k, scores, marker='o')
plt.title("Méthode du silhouette")
plt.xlabel("Nombre de clusters (k)")
plt.ylabel("Score de silhouette")
plt.grid(True)
plt.show()
kmeans = KMeans(n_clusters=5, random_state=42, n_init=10)
clusters = kmeans.fit_predict(df_pca_filtered[pc_columns])
df_pca_filtered['Cluster'] = pd.Categorical(clusters)
cluster_colors = {
0: "#e41a1c", # rouge
1: "#377eb8", # bleu
2: "#4daf4a", # vert
3: "#984ea3", # violet
4: "#ff7f00" # orange
}
fig = px.scatter(
df_pca_filtered,
x='PC1',
y='PC2',
color='Cluster',
hover_name='Zone',
title='ACP + Clustering K-means (k=5)',
labels={'PC1': 'Composante principale 1', 'PC2': 'Composante principale 2', 'Cluster': 'Cluster'},
color_discrete_map=cluster_colors
)
fig.show()
df_cluster_0 = df_pca_filtered[df_pca_filtered['Cluster'] == 0]
df_cluster_1 = df_pca_filtered[df_pca_filtered['Cluster'] == 1]
df_cluster_2 = df_pca_filtered[df_pca_filtered['Cluster'] == 2]
df_cluster_3 = df_pca_filtered[df_pca_filtered['Cluster'] == 3]
df_cluster_4 = df_pca_filtered[df_pca_filtered['Cluster'] == 4]
df_pca_filtered.head()
| PC1 | PC2 | PC3 | PC4 | PC5 | PC6 | PC7 | PC8 | Zone | Cluster | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | -1.06 | 2.41 | -1.37 | 0.14 | -0.96 | 0.32 | -0.97 | -0.27 | Afghanistan | 0 |
| 1 | 0.87 | -0.03 | 0.49 | 1.15 | 0.12 | -0.28 | -1.13 | -0.62 | Afrique du Sud | 4 |
| 2 | -0.70 | 0.57 | -0.69 | 0.16 | 0.13 | 0.18 | 0.24 | -0.71 | Algérie | 0 |
| 3 | 1.41 | -2.33 | 1.50 | 0.94 | -0.11 | -0.30 | -2.19 | 0.09 | Allemagne | 4 |
| 4 | -0.71 | 0.06 | -0.51 | 0.96 | 0.20 | 0.28 | -0.51 | -0.23 | Angola | 0 |
df_cluster_0.head()
| PC1 | PC2 | PC3 | PC4 | PC5 | PC6 | PC7 | PC8 | Zone | Cluster | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | -1.06 | 2.41 | -1.37 | 0.14 | -0.96 | 0.32 | -0.97 | -0.27 | Afghanistan | 0 |
| 2 | -0.70 | 0.57 | -0.69 | 0.16 | 0.13 | 0.18 | 0.24 | -0.71 | Algérie | 0 |
| 4 | -0.71 | 0.06 | -0.51 | 0.96 | 0.20 | 0.28 | -0.51 | -0.23 | Angola | 0 |
| 6 | 0.81 | 0.11 | 0.41 | -0.33 | 0.49 | 0.17 | 0.67 | -0.19 | Argentine | 0 |
| 9 | -0.88 | 0.72 | -0.25 | -0.67 | -0.68 | 0.01 | -0.27 | 0.30 | Azerbaïdjan | 0 |
df_cluster_2.head()
| PC1 | PC2 | PC3 | PC4 | PC5 | PC6 | PC7 | PC8 | Zone | Cluster | |
|---|---|---|---|---|---|---|---|---|---|---|
| 13 | -1.37 | 0.38 | 1.16 | -1.42 | -1.96 | 2.94 | 0.12 | -0.41 | Bosnie-Herzégovine | 2 |
| 15 | -0.87 | -0.45 | 0.89 | -0.96 | -0.92 | 1.02 | 0.06 | -0.12 | Bulgarie | 2 |
| 16 | -0.90 | -0.07 | 0.86 | -1.15 | -1.28 | 2.25 | 0.22 | -0.08 | Bélarus | 2 |
| 28 | 0.11 | -1.08 | 1.91 | -0.17 | -0.60 | 3.76 | 0.31 | -0.83 | Espagne | 2 |
df_volaille_brut.head()
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afghanistan | 0.00 | -2.79 | 4.16 | 2,956.80 | 57.00 | 0.00 | 29.00 | 55.00 | 2.00 | 28.00 | 57.00 | 36,296,113.00 | 2017 | 2.66 | 2.24 |
| 1 | Afrique du Sud | 0.00 | -0.28 | 0.82 | 14,823.60 | 2,118.00 | 63.00 | 514.00 | 2,035.00 | 83.00 | 1,667.00 | 2,181.00 | 57,009,756.00 | 2017 | 1.36 | -16.23 |
| 2 | Algérie | 0.00 | -0.92 | 1.00 | 13,805.40 | 277.00 | 0.00 | 2.00 | 264.00 | 13.00 | 275.00 | 277.00 | 41,389,189.00 | 2017 | 1.77 | -1.56 |
| 3 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 4 | Angola | 0.01 | -0.39 | 0.81 | 9,050.00 | 319.00 | 0.00 | 277.00 | 315.00 | 2.00 | 42.00 | 319.00 | 29,816,766.00 | 2017 | 3.32 | 2.80 |
df_final = df_volaille_brut[df_volaille_brut['Zone'].isin(df_cluster_2['Zone'])]
df_final.head(50)
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 13 | Bosnie-Herzégovine | 0.01 | -0.35 | 3.69 | 15,707.10 | 55.00 | 8.00 | 10.00 | 56.00 | 0.00 | 61.00 | 63.00 | 3,351,525.00 | 2017 | -0.95 | 164.29 |
| 15 | Bulgarie | 0.14 | 0.32 | 2.80 | 25,875.60 | 157.00 | 45.00 | 108.00 | 157.00 | 0.00 | 107.00 | 202.00 | 7,102,444.00 | 2017 | -0.61 | 69.45 |
| 16 | Bélarus | 0.03 | -0.06 | 3.13 | 25,504.00 | 265.00 | 152.00 | 21.00 | 264.00 | 0.00 | 463.00 | 417.00 | 9,450,231.00 | 2017 | -0.05 | 121.59 |
| 28 | Espagne | 0.00 | 0.27 | 0.19 | 45,021.80 | 1,497.00 | 212.00 | 205.00 | 1,418.00 | 66.00 | 1,515.00 | 1,709.00 | 46,647,428.00 | 2017 | 0.33 | 178.07 |
colonnes = "Zone"
df_cluster_4 = df_cluster_4['Zone']
df_cluster_4 = pd.merge(df_cluster_4, df_volaille_brut, on="Zone")
df_cluster_4.head()
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afrique du Sud | 0.00 | -0.28 | 0.82 | 14,823.60 | 2,118.00 | 63.00 | 514.00 | 2,035.00 | 83.00 | 1,667.00 | 2,181.00 | 57,009,756.00 | 2017 | 1.36 | -16.23 |
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 2 | Arabie saoudite | 0.00 | -0.65 | 0.99 | 48,554.40 | 1,435.00 | 10.00 | 722.00 | 1,435.00 | 0.00 | 616.00 | 1,445.00 | 33,101,179.00 | 2017 | 2.49 | 13.21 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 |
| 4 | France | 0.14 | 0.27 | 0.47 | 53,398.30 | 1,573.00 | 501.00 | 506.00 | 1,485.00 | 0.00 | 1,750.00 | 2,074.00 | 64,842,509.00 | 2017 | 0.42 | -61.47 |
len(df_cluster_4)
8
df_cluster_4.head(len(df_cluster_4))
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afrique du Sud | 0.00 | -0.28 | 0.82 | 14,823.60 | 2,118.00 | 63.00 | 514.00 | 2,035.00 | 83.00 | 1,667.00 | 2,181.00 | 57,009,756.00 | 2017 | 1.36 | -16.23 |
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 2 | Arabie saoudite | 0.00 | -0.65 | 0.99 | 48,554.40 | 1,435.00 | 10.00 | 722.00 | 1,435.00 | 0.00 | 616.00 | 1,445.00 | 33,101,179.00 | 2017 | 2.49 | 13.21 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 |
| 4 | France | 0.14 | 0.27 | 0.47 | 53,398.30 | 1,573.00 | 501.00 | 506.00 | 1,485.00 | 0.00 | 1,750.00 | 2,074.00 | 64,842,509.00 | 2017 | 0.42 | -61.47 |
| 5 | Fédération de Russie | 0.00 | -0.64 | 1.70 | 36,011.80 | 4,556.00 | 115.00 | 226.00 | 4,509.00 | 0.00 | 4,444.00 | 4,671.00 | 145,530,082.00 | 2017 | 0.12 | -1.55 |
| 6 | Japon | 0.12 | 1.10 | 0.64 | 44,491.10 | 2,415.00 | 10.00 | 1,069.00 | 2,359.00 | 56.00 | 2,215.00 | 2,425.00 | 127,502,725.00 | 2017 | -0.07 | 0.16 |
| 7 | Royaume-Uni de Grande-Bretagne et d'Irlande du... | 0.23 | 0.38 | 0.56 | 53,399.00 | 2,234.00 | 359.00 | 779.00 | 2,131.00 | 0.00 | 1,814.00 | 2,593.00 | 66,727,461.00 | 2017 | 0.76 | 12.97 |
df_cluster_4.describe()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 | 8.00 |
| mean | 0.06 | 0.20 | 1.12 | 47,238.06 | 2,043.75 | 295.88 | 695.62 | 1,994.25 | 17.38 | 1,755.50 | 2,339.62 | 73,084,805.38 | 2,017.00 | 0.73 | -7.49 |
| std | 0.09 | 0.66 | 0.65 | 16,065.04 | 1,212.25 | 281.28 | 267.97 | 1,181.30 | 32.97 | 1,298.64 | 1,092.54 | 45,659,515.85 | 0.00 | 0.84 | 23.80 |
| min | 0.00 | -0.65 | 0.47 | 14,823.60 | 280.00 | 10.00 | 226.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2,017.00 | -0.07 | -61.47 |
| 25% | 0.00 | -0.37 | 0.62 | 42,371.28 | 1,538.50 | 49.75 | 512.00 | 1,472.50 | 0.00 | 1,289.50 | 1,916.75 | 51,032,611.75 | 2,017.00 | 0.15 | -7.53 |
| 50% | 0.00 | 0.33 | 0.91 | 50,976.35 | 1,928.50 | 237.00 | 750.50 | 1,822.00 | 0.00 | 1,708.50 | 2,283.00 | 65,784,985.00 | 2,017.00 | 0.52 | -1.97 |
| 75% | 0.13 | 0.63 | 1.48 | 55,440.15 | 2,279.25 | 537.25 | 858.25 | 2,188.00 | 14.00 | 1,914.25 | 2,467.00 | 93,869,488.00 | 2,017.00 | 0.91 | 3.36 |
| max | 0.23 | 1.10 | 2.35 | 65,662.70 | 4,556.00 | 663.00 | 1,069.00 | 4,509.00 | 83.00 | 4,444.00 | 4,671.00 | 145,530,082.00 | 2,017.00 | 2.49 | 13.21 |
df_cluster_1 = df_cluster_1['Zone']
df_cluster_1 = pd.merge(df_cluster_1, df_volaille_brut, on="Zone")
df_cluster_1.describe()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 | 27.00 |
| mean | 0.17 | 0.74 | 0.73 | 49,668.63 | 368.48 | 115.52 | 99.56 | 361.96 | 1.67 | 419.30 | 484.00 | 13,637,731.93 | 2,017.00 | 0.90 | -2.44 |
| std | 0.48 | 0.40 | 1.75 | 17,967.89 | 410.68 | 223.13 | 96.97 | 410.62 | 6.13 | 562.79 | 536.85 | 15,349,459.33 | 0.00 | 1.49 | 10.96 |
| min | 0.00 | -0.08 | -3.60 | 9,990.60 | 52.00 | 0.00 | 1.00 | 51.00 | 0.00 | 7.00 | 76.00 | 1,384,059.00 | 2,017.00 | -1.26 | -36.27 |
| 25% | 0.00 | 0.41 | 0.16 | 36,570.15 | 121.00 | 14.00 | 37.50 | 113.00 | 0.00 | 96.00 | 143.50 | 4,727,656.50 | 2,017.00 | 0.27 | -2.32 |
| 50% | 0.02 | 0.85 | 0.61 | 46,530.10 | 173.00 | 35.00 | 82.00 | 164.00 | 0.00 | 157.00 | 221.00 | 8,819,901.00 | 2,017.00 | 0.50 | -0.29 |
| 75% | 0.09 | 1.01 | 1.56 | 60,415.40 | 368.50 | 104.50 | 129.50 | 363.50 | 0.00 | 478.00 | 646.50 | 11,030,391.00 | 2,017.00 | 1.02 | 1.05 |
| max | 2.34 | 1.56 | 3.76 | 85,225.20 | 1,433.00 | 1,025.00 | 433.00 | 1,433.00 | 27.00 | 2,351.00 | 2,181.00 | 60,673,701.00 | 2,017.00 | 4.96 | 17.68 |
df_cluster_0 = df_cluster_0['Zone']
df_cluster_0 = pd.merge(df_cluster_0, df_volaille_brut, on="Zone")
df_cluster_0.describe()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 | 59.00 |
| mean | 1.70 | -0.65 | 2.62 | 12,398.58 | 518.32 | 32.83 | 53.22 | 473.46 | 18.92 | 505.24 | 551.15 | 40,140,934.85 | 2,017.00 | 1.64 | inf |
| std | 12.09 | 0.73 | 1.62 | 9,470.40 | 632.54 | 123.21 | 89.24 | 577.69 | 47.48 | 678.16 | 678.98 | 52,264,515.96 | 0.00 | 1.02 | NaN |
| min | 0.00 | -2.79 | -1.02 | 1,510.40 | 52.00 | 0.00 | 0.00 | 52.00 | 0.00 | 4.00 | 52.00 | 2,064,823.00 | 2,017.00 | -0.65 | -128.01 |
| 25% | 0.00 | -0.98 | 1.50 | 4,967.95 | 86.00 | 0.00 | 1.50 | 84.00 | 0.00 | 64.50 | 89.50 | 10,179,212.00 | 2,017.00 | 1.06 | -6.37 |
| 50% | 0.01 | -0.57 | 2.70 | 10,184.00 | 202.00 | 0.00 | 12.00 | 195.00 | 2.00 | 171.00 | 202.00 | 21,128,032.00 | 2,017.00 | 1.50 | -0.30 |
| 75% | 0.07 | -0.08 | 3.75 | 16,462.60 | 691.00 | 4.00 | 72.00 | 558.50 | 11.00 | 695.50 | 693.00 | 42,663,164.50 | 2,017.00 | 2.58 | 3.36 |
| max | 92.94 | 0.60 | 7.45 | 42,936.40 | 2,323.00 | 796.00 | 470.00 | 2,220.00 | 316.00 | 2,301.00 | 2,323.00 | 264,650,963.00 | 2,017.00 | 4.00 | inf |
df_cluster_2 = df_cluster_2['Zone']
df_cluster_2 = pd.merge(df_cluster_2, df_volaille_brut, on="Zone")
df_cluster_2.describe()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 | 4.00 |
| mean | 0.04 | 0.05 | 2.45 | 28,027.12 | 493.50 | 104.25 | 86.00 | 473.75 | 16.50 | 536.50 | 597.75 | 16,637,907.00 | 2,017.00 | -0.32 | 133.35 |
| std | 0.06 | 0.31 | 1.55 | 12,269.16 | 674.47 | 94.28 | 90.64 | 635.20 | 33.00 | 676.62 | 755.01 | 20,163,391.23 | 0.00 | 0.57 | 48.92 |
| min | 0.00 | -0.35 | 0.19 | 15,707.10 | 55.00 | 8.00 | 10.00 | 56.00 | 0.00 | 61.00 | 63.00 | 3,351,525.00 | 2,017.00 | -0.95 | 69.45 |
| 25% | 0.01 | -0.13 | 2.15 | 23,054.78 | 131.50 | 35.75 | 18.25 | 131.75 | 0.00 | 95.50 | 167.25 | 6,164,714.25 | 2,017.00 | -0.69 | 108.56 |
| 50% | 0.02 | 0.11 | 2.96 | 25,689.80 | 211.00 | 98.50 | 64.50 | 210.50 | 0.00 | 285.00 | 309.50 | 8,276,337.50 | 2,017.00 | -0.33 | 142.94 |
| 75% | 0.06 | 0.28 | 3.27 | 30,662.15 | 573.00 | 167.00 | 132.25 | 552.50 | 16.50 | 726.00 | 740.00 | 18,749,530.25 | 2,017.00 | 0.04 | 167.74 |
| max | 0.14 | 0.32 | 3.69 | 45,021.80 | 1,497.00 | 212.00 | 205.00 | 1,418.00 | 66.00 | 1,515.00 | 1,709.00 | 46,647,428.00 | 2,017.00 | 0.33 | 178.07 |
colonnes = ["Zone", "Cluster"]
df_pca_filtered = df_pca_filtered[colonnes]
df_pca_filtered.head()
| Zone | Cluster | |
|---|---|---|
| 0 | Afghanistan | 0 |
| 1 | Afrique du Sud | 4 |
| 2 | Algérie | 0 |
| 3 | Allemagne | 4 |
| 4 | Angola | 0 |
df_cluster_global = pd.merge(df_volaille_brut, df_pca_filtered, on="Zone")
df_cluster_global.head()
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | Cluster | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afghanistan | 0.00 | -2.79 | 4.16 | 2,956.80 | 57.00 | 0.00 | 29.00 | 55.00 | 2.00 | 28.00 | 57.00 | 36,296,113.00 | 2017 | 2.66 | 2.24 | 0 |
| 1 | Afrique du Sud | 0.00 | -0.28 | 0.82 | 14,823.60 | 2,118.00 | 63.00 | 514.00 | 2,035.00 | 83.00 | 1,667.00 | 2,181.00 | 57,009,756.00 | 2017 | 1.36 | -16.23 | 4 |
| 2 | Algérie | 0.00 | -0.92 | 1.00 | 13,805.40 | 277.00 | 0.00 | 2.00 | 264.00 | 13.00 | 275.00 | 277.00 | 41,389,189.00 | 2017 | 1.77 | -1.56 | 0 |
| 3 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 | 4 |
| 4 | Angola | 0.01 | -0.39 | 0.81 | 9,050.00 | 319.00 | 0.00 | 277.00 | 315.00 | 2.00 | 42.00 | 319.00 | 29,816,766.00 | 2017 | 3.32 | 2.80 | 0 |
counts = df_cluster_global['Cluster'].value_counts()
print(counts)
Cluster 0 59 1 27 4 8 2 4 3 1 Name: count, dtype: int64
df_cluster_global = pd.merge(df_cluster_global, counts, on="Cluster")
df_cluster_global.head()
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | Cluster | count | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afghanistan | 0.00 | -2.79 | 4.16 | 2,956.80 | 57.00 | 0.00 | 29.00 | 55.00 | 2.00 | 28.00 | 57.00 | 36,296,113.00 | 2017 | 2.66 | 2.24 | 0 | 59 |
| 1 | Algérie | 0.00 | -0.92 | 1.00 | 13,805.40 | 277.00 | 0.00 | 2.00 | 264.00 | 13.00 | 275.00 | 277.00 | 41,389,189.00 | 2017 | 1.77 | -1.56 | 0 | 59 |
| 2 | Angola | 0.01 | -0.39 | 0.81 | 9,050.00 | 319.00 | 0.00 | 277.00 | 315.00 | 2.00 | 42.00 | 319.00 | 29,816,766.00 | 2017 | 3.32 | 2.80 | 0 | 59 |
| 3 | Argentine | 0.00 | 0.16 | 1.32 | 28,499.00 | 1,962.00 | 207.00 | 8.00 | 1,856.00 | 106.00 | 2,161.00 | 2,169.00 | 43,937,140.00 | 2017 | 0.94 | 0.00 | 0 | 59 |
| 4 | Azerbaïdjan | 0.02 | -0.75 | 3.94 | 19,676.00 | 129.00 | 0.00 | 27.00 | 129.00 | 0.00 | 104.00 | 129.00 | 9,845,320.00 | 2017 | 1.10 | 5.90 | 0 | 59 |
df_cluster_global = df_cluster_global.drop(columns=['Zone', 'Année'])
df_cluster_global = df_cluster_global.groupby('Cluster').mean()
df_cluster_global = df_cluster_global.round(2)
df_cluster_global.head()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | croissance de la population en % | croissance de la stabilité politique en % | count | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Cluster | |||||||||||||||
| 0 | 1.70 | -0.65 | 2.62 | 12,398.58 | 518.32 | 32.83 | 53.22 | 473.46 | 18.92 | 505.24 | 551.15 | 40,140,934.85 | 1.64 | NaN | 59.00 |
| 1 | 0.17 | 0.74 | 0.73 | 49,668.63 | 368.48 | 115.52 | 99.56 | 361.96 | 1.67 | 419.30 | 484.00 | 13,637,731.93 | 0.90 | -2.44 | 27.00 |
| 2 | 0.04 | 0.05 | 2.45 | 28,027.12 | 493.50 | 104.25 | 86.00 | 473.75 | 16.50 | 536.50 | 597.75 | 16,637,907.00 | -0.32 | 133.35 | 4.00 |
| 3 | 149.42 | -0.81 | 0.39 | 22,162.20 | 4,219.00 | 9.00 | 972.00 | 4,058.00 | 161.00 | 3,249.00 | 4,228.00 | 124,777,324.00 | 1.24 | 3.16 | 1.00 |
| 4 | 0.06 | 0.20 | 1.12 | 47,238.06 | 2,043.75 | 295.88 | 695.62 | 1,994.25 | 17.38 | 1,755.50 | 2,339.62 | 73,084,805.38 | 0.73 | -7.49 | 8.00 |
df_cluster_global = df_cluster_global.fillna(0)
df_cluster_global.head()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | croissance de la population en % | croissance de la stabilité politique en % | count | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Cluster | |||||||||||||||
| 0 | 1.70 | -0.65 | 2.62 | 12,398.58 | 518.32 | 32.83 | 53.22 | 473.46 | 18.92 | 505.24 | 551.15 | 40,140,934.85 | 1.64 | 0.00 | 59.00 |
| 1 | 0.17 | 0.74 | 0.73 | 49,668.63 | 368.48 | 115.52 | 99.56 | 361.96 | 1.67 | 419.30 | 484.00 | 13,637,731.93 | 0.90 | -2.44 | 27.00 |
| 2 | 0.04 | 0.05 | 2.45 | 28,027.12 | 493.50 | 104.25 | 86.00 | 473.75 | 16.50 | 536.50 | 597.75 | 16,637,907.00 | -0.32 | 133.35 | 4.00 |
| 3 | 149.42 | -0.81 | 0.39 | 22,162.20 | 4,219.00 | 9.00 | 972.00 | 4,058.00 | 161.00 | 3,249.00 | 4,228.00 | 124,777,324.00 | 1.24 | 3.16 | 1.00 |
| 4 | 0.06 | 0.20 | 1.12 | 47,238.06 | 2,043.75 | 295.88 | 695.62 | 1,994.25 | 17.38 | 1,755.50 | 2,339.62 | 73,084,805.38 | 0.73 | -7.49 | 8.00 |
df_cluster_global[['count']].plot(kind='bar')
<Axes: xlabel='Cluster'>
fig = px.bar(df_cluster_global, x=df_cluster_global.index, y="count",color=df_cluster_global.index.astype(str),
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5))
fig.show()
fig = px.bar(df_cluster_global, x=df_cluster_global.index, y="Population",color=df_cluster_global.index.astype(str),
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5))
fig.show()
fig = px.bar(df_cluster_global, x=df_cluster_global.index, y="Stabilité politique en 2017",color=df_cluster_global.index.astype(str),
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5))
fig.show()
df_cluster_global[['PIB par habitant']].plot(kind='bar')
<Axes: xlabel='Cluster'>
df_cluster_global = df_cluster_global[~df_cluster_global.index.isin([0, 3])]
df_cluster_global.head()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | croissance de la population en % | croissance de la stabilité politique en % | count | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Cluster | |||||||||||||||
| 1 | 0.17 | 0.74 | 0.73 | 49,668.63 | 368.48 | 115.52 | 99.56 | 361.96 | 1.67 | 419.30 | 484.00 | 13,637,731.93 | 0.90 | -2.44 | 27.00 |
| 2 | 0.04 | 0.05 | 2.45 | 28,027.12 | 493.50 | 104.25 | 86.00 | 473.75 | 16.50 | 536.50 | 597.75 | 16,637,907.00 | -0.32 | 133.35 | 4.00 |
| 4 | 0.06 | 0.20 | 1.12 | 47,238.06 | 2,043.75 | 295.88 | 695.62 | 1,994.25 | 17.38 | 1,755.50 | 2,339.62 | 73,084,805.38 | 0.73 | -7.49 | 8.00 |
fig = px.bar(df_cluster_global, x=df_cluster_global.index.astype(str), y='PIB par habitant',color=df_cluster_global.index.astype(str),
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster", "x":"Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
tickmode='array',
tickvals=df_cluster_global.index.tolist()
))
fig.show()
fig = px.bar(df_cluster_global, x=df_cluster_global.index.astype(str), y='Disponibilité intérieure',color=df_cluster_global.index.astype(str),
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster", "x":"Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
tickmode='array',
tickvals=df_cluster_global.index.tolist()
))
fig.show()
fig = go.Figure()
for col in ['Importations - Quantité','Production']:
fig.add_trace(go.Bar(
name=col,
x=df_cluster_global.index,
y=df_cluster_global[col]
))
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
type='category'
),barmode='stack'
)
fig.show()
df_cluster_global.head()
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | croissance de la population en % | croissance de la stabilité politique en % | count | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Cluster | |||||||||||||||
| 1 | 0.17 | 0.74 | 0.73 | 49,668.63 | 368.48 | 115.52 | 99.56 | 361.96 | 1.67 | 419.30 | 484.00 | 13,637,731.93 | 0.90 | -2.44 | 27.00 |
| 2 | 0.04 | 0.05 | 2.45 | 28,027.12 | 493.50 | 104.25 | 86.00 | 473.75 | 16.50 | 536.50 | 597.75 | 16,637,907.00 | -0.32 | 133.35 | 4.00 |
| 4 | 0.06 | 0.20 | 1.12 | 47,238.06 | 2,043.75 | 295.88 | 695.62 | 1,994.25 | 17.38 | 1,755.50 | 2,339.62 | 73,084,805.38 | 0.73 | -7.49 | 8.00 |
df_cluster_global['pourcentage importation'] = df_cluster_global['Importations - Quantité'] / df_cluster_global['Disponibilité intérieure'] * 100
df_cluster_global
| émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | croissance de la population en % | croissance de la stabilité politique en % | count | pourcentage importation | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Cluster | ||||||||||||||||
| 1 | 0.17 | 0.74 | 0.73 | 49,668.63 | 368.48 | 115.52 | 99.56 | 361.96 | 1.67 | 419.30 | 484.00 | 13,637,731.93 | 0.90 | -2.44 | 27.00 | 27.02 |
| 2 | 0.04 | 0.05 | 2.45 | 28,027.12 | 493.50 | 104.25 | 86.00 | 473.75 | 16.50 | 536.50 | 597.75 | 16,637,907.00 | -0.32 | 133.35 | 4.00 | 17.43 |
| 4 | 0.06 | 0.20 | 1.12 | 47,238.06 | 2,043.75 | 295.88 | 695.62 | 1,994.25 | 17.38 | 1,755.50 | 2,339.62 | 73,084,805.38 | 0.73 | -7.49 | 8.00 | 34.04 |
df_cluster_4
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Afrique du Sud | 0.00 | -0.28 | 0.82 | 14,823.60 | 2,118.00 | 63.00 | 514.00 | 2,035.00 | 83.00 | 1,667.00 | 2,181.00 | 57,009,756.00 | 2017 | 1.36 | -16.23 |
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 2 | Arabie saoudite | 0.00 | -0.65 | 0.99 | 48,554.40 | 1,435.00 | 10.00 | 722.00 | 1,435.00 | 0.00 | 616.00 | 1,445.00 | 33,101,179.00 | 2017 | 2.49 | 13.21 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 |
| 4 | France | 0.14 | 0.27 | 0.47 | 53,398.30 | 1,573.00 | 501.00 | 506.00 | 1,485.00 | 0.00 | 1,750.00 | 2,074.00 | 64,842,509.00 | 2017 | 0.42 | -61.47 |
| 5 | Fédération de Russie | 0.00 | -0.64 | 1.70 | 36,011.80 | 4,556.00 | 115.00 | 226.00 | 4,509.00 | 0.00 | 4,444.00 | 4,671.00 | 145,530,082.00 | 2017 | 0.12 | -1.55 |
| 6 | Japon | 0.12 | 1.10 | 0.64 | 44,491.10 | 2,415.00 | 10.00 | 1,069.00 | 2,359.00 | 56.00 | 2,215.00 | 2,425.00 | 127,502,725.00 | 2017 | -0.07 | 0.16 |
| 7 | Royaume-Uni de Grande-Bretagne et d'Irlande du... | 0.23 | 0.38 | 0.56 | 53,399.00 | 2,234.00 | 359.00 | 779.00 | 2,131.00 | 0.00 | 1,814.00 | 2,593.00 | 66,727,461.00 | 2017 | 0.76 | 12.97 |
fig = px.bar(df_cluster_4, x="Stabilité politique en 2017", y='Zone',color=df_cluster_4['Zone'],
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Pays", "x":"Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=1200, height=500, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
tickmode='array',
tickvals=df_cluster_4.index.tolist(),
tickangle=-45
))
fig.show()
df_cluster_4_filtered = df_cluster_4.loc[df_cluster_4['Stabilité politique en 2017'] > 0]
df_cluster_4_filtered
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 |
| 4 | France | 0.14 | 0.27 | 0.47 | 53,398.30 | 1,573.00 | 501.00 | 506.00 | 1,485.00 | 0.00 | 1,750.00 | 2,074.00 | 64,842,509.00 | 2017 | 0.42 | -61.47 |
| 6 | Japon | 0.12 | 1.10 | 0.64 | 44,491.10 | 2,415.00 | 10.00 | 1,069.00 | 2,359.00 | 56.00 | 2,215.00 | 2,425.00 | 127,502,725.00 | 2017 | -0.07 | 0.16 |
| 7 | Royaume-Uni de Grande-Bretagne et d'Irlande du... | 0.23 | 0.38 | 0.56 | 53,399.00 | 2,234.00 | 359.00 | 779.00 | 2,131.00 | 0.00 | 1,814.00 | 2,593.00 | 66,727,461.00 | 2017 | 0.76 | 12.97 |
df_cluster_2
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Bosnie-Herzégovine | 0.01 | -0.35 | 3.69 | 15,707.10 | 55.00 | 8.00 | 10.00 | 56.00 | 0.00 | 61.00 | 63.00 | 3,351,525.00 | 2017 | -0.95 | 164.29 |
| 1 | Bulgarie | 0.14 | 0.32 | 2.80 | 25,875.60 | 157.00 | 45.00 | 108.00 | 157.00 | 0.00 | 107.00 | 202.00 | 7,102,444.00 | 2017 | -0.61 | 69.45 |
| 2 | Bélarus | 0.03 | -0.06 | 3.13 | 25,504.00 | 265.00 | 152.00 | 21.00 | 264.00 | 0.00 | 463.00 | 417.00 | 9,450,231.00 | 2017 | -0.05 | 121.59 |
| 3 | Espagne | 0.00 | 0.27 | 0.19 | 45,021.80 | 1,497.00 | 212.00 | 205.00 | 1,418.00 | 66.00 | 1,515.00 | 1,709.00 | 46,647,428.00 | 2017 | 0.33 | 178.07 |
def barplot(df, x, y):
fig = px.bar(df, x=x, y=y,color=df_cluster_2.index.astype(str),
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster", "x":"Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
tickmode='array',
tickvals=df_cluster_2.index.tolist()
))
fig.show()
barplot(df_cluster_2, "Zone", "PIB par habitant")
fig = go.Figure()
for col in ['Importations - Quantité','Production']:
fig.add_trace(go.Bar(
name=col,
x=df_cluster_2['Zone'],
y=df_cluster_2[col]
))
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
type='category'
),barmode='stack'
)
fig.show()
df_cluster_4_filtered
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 |
| 4 | France | 0.14 | 0.27 | 0.47 | 53,398.30 | 1,573.00 | 501.00 | 506.00 | 1,485.00 | 0.00 | 1,750.00 | 2,074.00 | 64,842,509.00 | 2017 | 0.42 | -61.47 |
| 6 | Japon | 0.12 | 1.10 | 0.64 | 44,491.10 | 2,415.00 | 10.00 | 1,069.00 | 2,359.00 | 56.00 | 2,215.00 | 2,425.00 | 127,502,725.00 | 2017 | -0.07 | 0.16 |
| 7 | Royaume-Uni de Grande-Bretagne et d'Irlande du... | 0.23 | 0.38 | 0.56 | 53,399.00 | 2,234.00 | 359.00 | 779.00 | 2,131.00 | 0.00 | 1,814.00 | 2,593.00 | 66,727,461.00 | 2017 | 0.76 | 12.97 |
df_cluster_4_filtered = df_cluster_4_filtered[df_cluster_4_filtered["Zone"] != "France"]
df_cluster_4_filtered
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 |
| 6 | Japon | 0.12 | 1.10 | 0.64 | 44,491.10 | 2,415.00 | 10.00 | 1,069.00 | 2,359.00 | 56.00 | 2,215.00 | 2,425.00 | 127,502,725.00 | 2017 | -0.07 | 0.16 |
| 7 | Royaume-Uni de Grande-Bretagne et d'Irlande du... | 0.23 | 0.38 | 0.56 | 53,399.00 | 2,234.00 | 359.00 | 779.00 | 2,131.00 | 0.00 | 1,814.00 | 2,593.00 | 66,727,461.00 | 2017 | 0.76 | 12.97 |
fig = go.Figure()
for col in ['Importations - Quantité','Production']:
fig.add_trace(go.Bar(
name=col,
x=df_cluster_4_filtered[col],
y=df_cluster_4_filtered["Zone"],
orientation='h'
))
fig.update_traces(width=0.5)
fig.update_layout(width=1000, height=400, bargap=0.05, margin=dict(l=5, r=5), barmode='stack')
fig.show()
df_cluster_4_filtered['pourcentage importation'] = df_cluster_4_filtered['Importations - Quantité']/( df_cluster_4_filtered['Production'] + df_cluster_4_filtered['Importations - Quantité']) * 100
df_cluster_4_filtered
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | pourcentage importation | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Allemagne | 0.00 | 0.57 | 1.41 | 61,563.60 | 1,739.00 | 646.00 | 842.00 | 1,609.00 | 0.00 | 1,514.00 | 2,385.00 | 82,658,409.00 | 2017 | 0.15 | -4.63 | 35.74 |
| 3 | Chine - RAS de Hong-Kong | 0.00 | 0.82 | 2.35 | 65,662.70 | 280.00 | 663.00 | 907.00 | 391.00 | 0.00 | 24.00 | 943.00 | 7,306,322.00 | 2017 | 0.62 | -2.38 | 97.42 |
| 6 | Japon | 0.12 | 1.10 | 0.64 | 44,491.10 | 2,415.00 | 10.00 | 1,069.00 | 2,359.00 | 56.00 | 2,215.00 | 2,425.00 | 127,502,725.00 | 2017 | -0.07 | 0.16 | 32.55 |
| 7 | Royaume-Uni de Grande-Bretagne et d'Irlande du... | 0.23 | 0.38 | 0.56 | 53,399.00 | 2,234.00 | 359.00 | 779.00 | 2,131.00 | 0.00 | 1,814.00 | 2,593.00 | 66,727,461.00 | 2017 | 0.76 | 12.97 | 30.04 |
df_pca_outliers
| PC1 | PC2 | PC3 | PC4 | PC5 | PC6 | PC7 | PC8 | Zone | |
|---|---|---|---|---|---|---|---|---|---|
| 14 | 10.37 | 0.09 | -4.00 | -1.09 | 0.31 | -2.36 | 0.28 | 0.04 | Brésil |
| 40 | 4.48 | 8.52 | 7.22 | 0.19 | 4.75 | -0.08 | 0.60 | -0.36 | Inde |
| 84 | -1.48 | 2.19 | -4.58 | 4.71 | 3.48 | 3.11 | -0.13 | 3.41 | Soudan |
| 102 | 15.08 | -1.28 | -2.04 | -1.35 | -0.80 | 2.67 | 0.53 | 0.34 | États-Unis d'Amérique |
df_pca_outliers = df_pca_outliers['Zone']
df_pca_outliers.head()
14 Brésil 40 Inde 84 Soudan 102 États-Unis d'Amérique Name: Zone, dtype: object
df_outliers = pd.merge(df_volaille_brut, df_pca_outliers, on="Zone")
df_outliers
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Brésil | 0.07 | -0.48 | 1.13 | 17,145.30 | 9,982.00 | 4,223.00 | 3.00 | 9,982.00 | 0.00 | 14,201.00 | 14,205.00 | 207,833,823.00 | 2017 | 0.83 | -186.71 |
| 1 | Inde | 0.02 | -0.77 | 5.40 | 7,363.80 | 3,661.00 | 4.00 | 0.00 | 2,965.00 | 695.00 | 3,545.00 | 3,665.00 | 1,338,676,785.00 | 2017 | 1.15 | -2.32 |
| 2 | Soudan | 0.03 | -1.97 | -0.39 | 4,264.10 | 69.00 | 0.00 | 2.00 | 65.00 | 3.00 | 67.00 | 69.00 | 40,813,397.00 | 2017 | 22.25 | -0.40 |
| 3 | États-Unis d'Amérique | 0.66 | 0.26 | 0.74 | 66,105.70 | 18,266.00 | 3,692.00 | 123.00 | 18,100.00 | 0.00 | 21,914.00 | 21,958.00 | 325,084,756.00 | 2017 | 0.73 | -1.79 |
fig = px.bar(df_outliers, x=df_outliers['Zone'], y="Stabilité politique en 2017",color=df_outliers['Zone'],
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=500, height=500, bargap=0.05, margin=dict(l=5, r=5))
fig.show()
fig = go.Figure()
for col in ['Importations - Quantité','Production']:
fig.add_trace(go.Bar(
name=col,
x=df_outliers[col],
y=df_outliers["Zone"],
orientation='h'
))
fig.update_traces(width=0.5)
fig.update_layout(width=1000, height=400, bargap=0.05, margin=dict(l=5, r=5), barmode='stack')
fig.show()
df_cluster_1
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Australie | 0.01 | 0.88 | 1.05 | 56,028.40 | 1,171.00 | 42.00 | 16.00 | 1,171.00 | 0.00 | 1,269.00 | 1,213.00 | 24,584,620.00 | 2017 | 1.50 | -0.05 |
| 1 | Autriche | 0.02 | 1.03 | 0.60 | 63,840.40 | 173.00 | 78.00 | 110.00 | 160.00 | 0.00 | 148.00 | 251.00 | 8,819,901.00 | 2017 | 0.54 | 0.38 |
| 2 | Belgique | 0.02 | 0.42 | 0.61 | 60,044.60 | 152.00 | 656.00 | 338.00 | 144.00 | 0.00 | 463.00 | 808.00 | 11,419,748.00 | 2017 | 0.60 | -4.87 |
| 3 | Canada | 0.05 | 1.09 | 0.58 | 55,589.80 | 1,433.00 | 163.00 | 182.00 | 1,433.00 | 0.00 | 1,417.00 | 1,596.00 | 36,732,095.00 | 2017 | 1.01 | 0.95 |
| 4 | Chili | 0.12 | 0.41 | 2.22 | 28,155.10 | 672.00 | 115.00 | 155.00 | 672.00 | 0.00 | 712.00 | 787.00 | 18,470,439.00 | 2017 | 1.05 | -0.94 |
| 5 | Danemark | 0.00 | 0.85 | 0.36 | 65,783.50 | 167.00 | 139.00 | 133.00 | 166.00 | 0.00 | 173.00 | 306.00 | 5,732,274.00 | 2017 | 0.42 | -1.65 |
| 6 | Finlande | 0.05 | 1.06 | 0.28 | 56,605.50 | 111.00 | 12.00 | 16.00 | 103.00 | 0.00 | 129.00 | 123.00 | 5,511,371.00 | 2017 | 0.35 | -2.88 |
| 7 | Grèce | 0.02 | -0.08 | -2.12 | 31,874.90 | 178.00 | 29.00 | 79.00 | 162.00 | 0.00 | 246.00 | 207.00 | 10,569,450.00 | 2017 | -0.47 | -21.61 |
| 8 | Hongrie | 0.00 | 0.80 | 1.41 | 33,940.30 | 266.00 | 210.00 | 58.00 | 246.00 | 18.00 | 493.00 | 476.00 | 9,729,823.00 | 2017 | -0.27 | -0.18 |
| 9 | Irlande | 0.13 | 0.99 | 2.91 | 85,225.20 | 128.00 | 93.00 | 99.00 | 123.00 | 0.00 | 110.00 | 221.00 | 4,753,279.00 | 2017 | 1.01 | -1.18 |
| 10 | Italie | 0.23 | 0.29 | -0.67 | 48,761.90 | 1,173.00 | 183.00 | 97.00 | 1,146.00 | 0.00 | 1,315.00 | 1,356.00 | 60,673,701.00 | 2017 | 0.27 | -3.43 |
| 11 | Jamaïque | 0.00 | 0.30 | -0.35 | 9,990.60 | 152.00 | 1.00 | 31.00 | 149.00 | 0.00 | 128.00 | 153.00 | 2,920,848.00 | 2017 | 0.49 | 17.68 |
| 12 | Koweït | 0.00 | -0.05 | -3.60 | 52,805.30 | 189.00 | 4.00 | 137.00 | 188.00 | 0.00 | 56.00 | 193.00 | 4,056,099.00 | 2017 | 4.38 | -36.27 |
| 13 | Lituanie | 0.00 | 0.77 | 3.76 | 39,736.10 | 82.00 | 68.00 | 44.00 | 80.00 | 0.00 | 118.00 | 150.00 | 2,845,414.00 | 2017 | -1.26 | -0.18 |
| 14 | Norvège | 0.00 | 1.15 | 0.19 | 85,144.10 | 102.00 | 0.00 | 2.00 | 101.00 | 0.00 | 101.00 | 102.00 | 5,296,326.00 | 2017 | 1.03 | -0.50 |
| 15 | Nouvelle-Zélande | 0.21 | 1.56 | 1.01 | 46,530.10 | 168.00 | 23.00 | 1.00 | 164.00 | 0.00 | 223.00 | 191.00 | 4,702,034.00 | 2017 | 0.97 | 2.25 |
| 16 | Oman | 0.02 | 0.75 | -0.79 | 38,844.30 | 114.00 | 16.00 | 126.00 | 101.00 | 0.00 | 7.00 | 130.00 | 4,665,928.00 | 2017 | 4.96 | 1.15 |
| 17 | Pologne | 0.01 | 0.51 | 3.75 | 34,689.40 | 1,156.00 | 1,025.00 | 55.00 | 1,150.00 | 27.00 | 2,351.00 | 2,181.00 | 37,953,180.00 | 2017 | -0.09 | 7.68 |
| 18 | Portugal | 0.04 | 1.11 | 0.46 | 38,100.70 | 325.00 | 44.00 | 82.00 | 315.00 | 0.00 | 361.00 | 369.00 | 10,288,527.00 | 2017 | -0.21 | 2.16 |
| 19 | République de Corée | 2.34 | 0.38 | 2.89 | 44,928.10 | 854.00 | 6.00 | 137.00 | 854.00 | 0.00 | 838.00 | 860.00 | 51,096,415.00 | 2017 | 0.35 | 10.28 |
| 20 | Slovaquie | 0.19 | 0.90 | 3.07 | 35,039.60 | 74.00 | 35.00 | 63.00 | 76.00 | 0.00 | 71.00 | 109.00 | 5,447,900.00 | 2017 | 0.08 | 2.63 |
| 21 | Slovénie | 0.00 | 0.87 | 1.05 | 42,331.50 | 52.00 | 29.00 | 20.00 | 51.00 | 0.00 | 72.00 | 81.00 | 2,076,394.00 | 2017 | 0.28 | -1.65 |
| 22 | Suisse | 0.00 | 1.24 | 0.69 | 78,328.10 | 133.00 | 4.00 | 51.00 | 133.00 | 0.00 | 91.00 | 137.00 | 8,455,804.00 | 2017 | 1.04 | -0.12 |
| 23 | Suède | 1.07 | 0.97 | 0.89 | 60,786.20 | 187.00 | 23.00 | 84.00 | 164.00 | 0.00 | 157.00 | 210.00 | 9,904,896.00 | 2017 | 0.71 | -2.31 |
| 24 | Tchéquie | 0.00 | 0.99 | 1.71 | 46,137.00 | 249.00 | 27.00 | 116.00 | 234.00 | 0.00 | 163.00 | 276.00 | 10,641,034.00 | 2017 | 0.27 | -0.29 |
| 25 | Trinité-et-Tobago | 0.00 | 0.27 | 0.12 | 31,763.70 | 76.00 | 0.00 | 23.00 | 75.00 | 0.00 | 61.00 | 76.00 | 1,384,059.00 | 2017 | 0.50 | -30.70 |
| 26 | Émirats arabes unis | 0.00 | 0.60 | -2.29 | 70,048.50 | 412.00 | 94.00 | 433.00 | 412.00 | 0.00 | 48.00 | 506.00 | 9,487,203.00 | 2017 | 4.85 | -2.33 |
df_cluster_1_sort_by_stab_politique = df_cluster_1.sort_values(by="Stabilité politique en 2017", ascending=True)
fig = px.bar(df_cluster_1_sort_by_stab_politique, x="Stabilité politique en 2017", y='Zone',color=df_cluster_1['Zone'],
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Pays", "x":"Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=1200, height=700, bargap=0.05, margin=dict(l=5, r=5),
xaxis=dict(
tickmode='array',
tickangle=-45
))
fig.show()
df_cluster_1 = df_cluster_1.loc[df_cluster_1['Stabilité politique en 2017'] >= 0]
df_cluster_1_sort_by_pib = df_cluster_1.sort_values(by="PIB par habitant", ascending=True)
fig = px.bar(df_cluster_1_sort_by_pib, x="PIB par habitant", y='Zone',color=df_cluster_1['Zone'],
color_discrete_sequence=px.colors.qualitative.Set1, labels={"color": "Pays", "x":"Cluster"})
fig.update_traces(width=0.5)
fig.update_layout(width=1200, height=700, bargap=0.05, margin=dict(l=5, r=5))
fig.show()
df_cluster_1_sort_by_importation = df_cluster_1.sort_values(by="Importations - Quantité", ascending=True)
fig = go.Figure()
for col in ['Importations - Quantité','Production']:
fig.add_trace(go.Bar(
name=col,
x=df_cluster_1_sort_by_importation[col],
y=df_cluster_1_sort_by_importation["Zone"],
orientation='h'
))
fig.update_traces(width=0.5)
fig.update_layout(width=1000, height=600, bargap=0.05, margin=dict(l=5, r=5), barmode='stack')
fig.show()
df_cluster_1_sort_by_importation['pourcentage importation'] = df_cluster_1_sort_by_importation['Importations - Quantité']/( df_cluster_1_sort_by_importation['Production'] + df_cluster_1_sort_by_importation['Importations - Quantité']) * 100
df_cluster_1_sort_by_importation
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | pourcentage importation | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 15 | Nouvelle-Zélande | 0.21 | 1.56 | 1.01 | 46,530.10 | 168.00 | 23.00 | 1.00 | 164.00 | 0.00 | 223.00 | 191.00 | 4,702,034.00 | 2017 | 0.97 | 2.25 | 0.45 |
| 14 | Norvège | 0.00 | 1.15 | 0.19 | 85,144.10 | 102.00 | 0.00 | 2.00 | 101.00 | 0.00 | 101.00 | 102.00 | 5,296,326.00 | 2017 | 1.03 | -0.50 | 1.94 |
| 6 | Finlande | 0.05 | 1.06 | 0.28 | 56,605.50 | 111.00 | 12.00 | 16.00 | 103.00 | 0.00 | 129.00 | 123.00 | 5,511,371.00 | 2017 | 0.35 | -2.88 | 11.03 |
| 0 | Australie | 0.01 | 0.88 | 1.05 | 56,028.40 | 1,171.00 | 42.00 | 16.00 | 1,171.00 | 0.00 | 1,269.00 | 1,213.00 | 24,584,620.00 | 2017 | 1.50 | -0.05 | 1.25 |
| 21 | Slovénie | 0.00 | 0.87 | 1.05 | 42,331.50 | 52.00 | 29.00 | 20.00 | 51.00 | 0.00 | 72.00 | 81.00 | 2,076,394.00 | 2017 | 0.28 | -1.65 | 21.74 |
| 25 | Trinité-et-Tobago | 0.00 | 0.27 | 0.12 | 31,763.70 | 76.00 | 0.00 | 23.00 | 75.00 | 0.00 | 61.00 | 76.00 | 1,384,059.00 | 2017 | 0.50 | -30.70 | 27.38 |
| 11 | Jamaïque | 0.00 | 0.30 | -0.35 | 9,990.60 | 152.00 | 1.00 | 31.00 | 149.00 | 0.00 | 128.00 | 153.00 | 2,920,848.00 | 2017 | 0.49 | 17.68 | 19.50 |
| 13 | Lituanie | 0.00 | 0.77 | 3.76 | 39,736.10 | 82.00 | 68.00 | 44.00 | 80.00 | 0.00 | 118.00 | 150.00 | 2,845,414.00 | 2017 | -1.26 | -0.18 | 27.16 |
| 22 | Suisse | 0.00 | 1.24 | 0.69 | 78,328.10 | 133.00 | 4.00 | 51.00 | 133.00 | 0.00 | 91.00 | 137.00 | 8,455,804.00 | 2017 | 1.04 | -0.12 | 35.92 |
| 17 | Pologne | 0.01 | 0.51 | 3.75 | 34,689.40 | 1,156.00 | 1,025.00 | 55.00 | 1,150.00 | 27.00 | 2,351.00 | 2,181.00 | 37,953,180.00 | 2017 | -0.09 | 7.68 | 2.29 |
| 8 | Hongrie | 0.00 | 0.80 | 1.41 | 33,940.30 | 266.00 | 210.00 | 58.00 | 246.00 | 18.00 | 493.00 | 476.00 | 9,729,823.00 | 2017 | -0.27 | -0.18 | 10.53 |
| 20 | Slovaquie | 0.19 | 0.90 | 3.07 | 35,039.60 | 74.00 | 35.00 | 63.00 | 76.00 | 0.00 | 71.00 | 109.00 | 5,447,900.00 | 2017 | 0.08 | 2.63 | 47.01 |
| 18 | Portugal | 0.04 | 1.11 | 0.46 | 38,100.70 | 325.00 | 44.00 | 82.00 | 315.00 | 0.00 | 361.00 | 369.00 | 10,288,527.00 | 2017 | -0.21 | 2.16 | 18.51 |
| 23 | Suède | 1.07 | 0.97 | 0.89 | 60,786.20 | 187.00 | 23.00 | 84.00 | 164.00 | 0.00 | 157.00 | 210.00 | 9,904,896.00 | 2017 | 0.71 | -2.31 | 34.85 |
| 10 | Italie | 0.23 | 0.29 | -0.67 | 48,761.90 | 1,173.00 | 183.00 | 97.00 | 1,146.00 | 0.00 | 1,315.00 | 1,356.00 | 60,673,701.00 | 2017 | 0.27 | -3.43 | 6.87 |
| 9 | Irlande | 0.13 | 0.99 | 2.91 | 85,225.20 | 128.00 | 93.00 | 99.00 | 123.00 | 0.00 | 110.00 | 221.00 | 4,753,279.00 | 2017 | 1.01 | -1.18 | 47.37 |
| 1 | Autriche | 0.02 | 1.03 | 0.60 | 63,840.40 | 173.00 | 78.00 | 110.00 | 160.00 | 0.00 | 148.00 | 251.00 | 8,819,901.00 | 2017 | 0.54 | 0.38 | 42.64 |
| 24 | Tchéquie | 0.00 | 0.99 | 1.71 | 46,137.00 | 249.00 | 27.00 | 116.00 | 234.00 | 0.00 | 163.00 | 276.00 | 10,641,034.00 | 2017 | 0.27 | -0.29 | 41.58 |
| 16 | Oman | 0.02 | 0.75 | -0.79 | 38,844.30 | 114.00 | 16.00 | 126.00 | 101.00 | 0.00 | 7.00 | 130.00 | 4,665,928.00 | 2017 | 4.96 | 1.15 | 94.74 |
| 5 | Danemark | 0.00 | 0.85 | 0.36 | 65,783.50 | 167.00 | 139.00 | 133.00 | 166.00 | 0.00 | 173.00 | 306.00 | 5,732,274.00 | 2017 | 0.42 | -1.65 | 43.46 |
| 19 | République de Corée | 2.34 | 0.38 | 2.89 | 44,928.10 | 854.00 | 6.00 | 137.00 | 854.00 | 0.00 | 838.00 | 860.00 | 51,096,415.00 | 2017 | 0.35 | 10.28 | 14.05 |
| 4 | Chili | 0.12 | 0.41 | 2.22 | 28,155.10 | 672.00 | 115.00 | 155.00 | 672.00 | 0.00 | 712.00 | 787.00 | 18,470,439.00 | 2017 | 1.05 | -0.94 | 17.88 |
| 3 | Canada | 0.05 | 1.09 | 0.58 | 55,589.80 | 1,433.00 | 163.00 | 182.00 | 1,433.00 | 0.00 | 1,417.00 | 1,596.00 | 36,732,095.00 | 2017 | 1.01 | 0.95 | 11.38 |
| 2 | Belgique | 0.02 | 0.42 | 0.61 | 60,044.60 | 152.00 | 656.00 | 338.00 | 144.00 | 0.00 | 463.00 | 808.00 | 11,419,748.00 | 2017 | 0.60 | -4.87 | 42.20 |
| 26 | Émirats arabes unis | 0.00 | 0.60 | -2.29 | 70,048.50 | 412.00 | 94.00 | 433.00 | 412.00 | 0.00 | 48.00 | 506.00 | 9,487,203.00 | 2017 | 4.85 | -2.33 | 90.02 |
df_cluster_1_sort_by_importation = df_cluster_1_sort_by_importation.loc[df_cluster_1_sort_by_importation['Importations - Quantité'] > 160]
df_cluster_1_sort_by_importation
| Zone | émission N2O / production | Stabilité politique en 2017 | croissance du PIB en % | PIB par habitant | Disponibilité intérieure | Exportations - Quantité | Importations - Quantité | Nourriture | Pertes | Production | Disponibilité intérieure - avant export | Population | Année | croissance de la population en % | croissance de la stabilité politique en % | pourcentage importation | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 3 | Canada | 0.05 | 1.09 | 0.58 | 55,589.80 | 1,433.00 | 163.00 | 182.00 | 1,433.00 | 0.00 | 1,417.00 | 1,596.00 | 36,732,095.00 | 2017 | 1.01 | 0.95 | 11.38 |
| 2 | Belgique | 0.02 | 0.42 | 0.61 | 60,044.60 | 152.00 | 656.00 | 338.00 | 144.00 | 0.00 | 463.00 | 808.00 | 11,419,748.00 | 2017 | 0.60 | -4.87 | 42.20 |
| 26 | Émirats arabes unis | 0.00 | 0.60 | -2.29 | 70,048.50 | 412.00 | 94.00 | 433.00 | 412.00 | 0.00 | 48.00 | 506.00 | 9,487,203.00 | 2017 | 4.85 | -2.33 | 90.02 |
df_cluster_1_sort_by_importation = df_cluster_1_sort_by_importation.sort_values(by="Importations - Quantité", ascending=True)
fig = go.Figure()
for col in ['Importations - Quantité','Production']:
fig.add_trace(go.Bar(
name=col,
x=df_cluster_1_sort_by_importation[col],
y=df_cluster_1_sort_by_importation["Zone"],
orientation='h'
))
fig.update_traces(width=0.5)
fig.update_layout(width=1000, height=600, bargap=0.05, margin=dict(l=5, r=5), barmode='stack')
fig.show()